package com.wm.wmim.server.controller;

import com.wm.wmim.server.api.bo.resp.UserInfoBO;
import com.wm.wmim.server.dto.bo.req.LoginReqBO;
import com.wm.wmim.server.dto.vo.resp.LoginRespVO;
import com.wm.wmim.server.mapstruct.UserInfoMapstruct;
import com.wm.wmim.server.service.UserInfoService;
import com.wm.wmim.server.dto.vo.req.LoginReqVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.wm.wmim.common.dto.RpcRespDTO.build;

/**
 * @author weiming
 * @date 2024/8/19 20:44
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;
    @Resource
    private UserInfoMapstruct userInfoMapstruct;


    @PostMapping("/signup")
    public Boolean signup(LoginReqVO reqVO){

        return true;
    }


    @PostMapping("/login")
    public LoginRespVO login(@RequestBody LoginReqVO reqVO) {
        LoginReqBO reqBO = userInfoMapstruct.fromVoToBo(reqVO);
        UserInfoBO login = userInfoService.login(reqBO);
        LoginRespVO loginRespVO = new LoginRespVO();
        loginRespVO.setUserId(login.getId());
        loginRespVO.setUserCode(login.getUserCode());
        loginRespVO.setToken("");
        loginRespVO.setNickname(login.getNickname());
        loginRespVO.setAvtar(login.getAvatar());
        return loginRespVO;
    }

}
